package com.dpj.test;

import lombok.extern.slf4j.Slf4j;

public class MultiplyLock {
    public static void main(String[] args) {
        BigRoom bigRoom=new BigRoom();
        new Thread(()->{
            try {
                bigRoom.study();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"小南").start();

        new Thread(()->{
            try {
                bigRoom.sleep();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"小女").start();

    }


}

@Slf4j(topic = "c.BigRoom")
class BigRoom{
    private final Object studyRoom=new Object();
    private final Object bedRoom=new Object();


    public void sleep() throws InterruptedException {
        synchronized (bedRoom){
            log.debug("sleeping 2小时");
            Thread.sleep(2000);
        }
    }

    public void study() throws InterruptedException {
        synchronized (studyRoom){
            log.debug("study 1小时");
            Thread.sleep(1000);
        }
    }
}
